<template>
  <div>
    <el-form v-model="fleetFormData" label-width="80px">
      <el-form-item label="车队名称:">
        <el-input v-model="fleetFormData.name"/>
      </el-form-item>

      <el-form-item label="负责人:">
        <el-select v-model="fleetFormData.manager">
          <el-option label="请选择" value=""/>
          <el-option v-for="(item,index) in userData" :key="index" :label="item.name" :value="item.id"/>
        </el-select>
      </el-form-item>

      <el-form-item label="所属机构:">
        <el-select v-model="fleetFormData.agencyId">
          <el-option label="请选择" value=""/>
          <el-option v-for="(item,index) in agencyData" :label="item.name" :value="item.id"/>
        </el-select>
      </el-form-item>

      <el-form-item label="状态">
        <el-radio label="1" border v-model="fleetFormData.status">正常</el-radio>
        <el-radio label="0" border v-model="fleetFormData.status">禁用</el-radio>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="addFleet">添加</el-button>
  </div>
</template>

<script>
import globalUser from '@/api/base/globalUser/index'
import coreOrg from '@/api/base/coreOrg/index'
import fleet from '@/api/base/fleet/index'

export default {
  name: 'add',
  data() {
    return {
      /**
       * 1.车队表单数据
       */
      fleetFormData: {
        name: '',
        agencyId: '',
        manager: '',
        status: '1'
      },
      userData: [],
      agencyData: []
    }
  }, methods: {
    addFleet() {
      fleet.addFleet(this.fleetFormData).then(data => {
        this.$message({
          type: 'success',
          showClose: true,
          message: '车队添加成功!'
        })
      })
      this.$router.push({path:"/fleet-index"})
    },
    //查询全部用户数据
    queryAllUserData() {
      globalUser.queryAll().then(data => {
        this.userData = data.data
      })
    },
    //查询全部机构数据
    queryAllAgency() {
      coreOrg.queryAll().then(data => {
        this.agencyData = data.data
      })
    }
  }, mounted() {
    this.queryAllUserData()
    this.queryAllAgency()
  }
}
</script>

<style scoped>

</style>
